//引入spu类型
import type { SpuData,HasSpuResponseData,AllTradMark,SpuHasImg,spuSaleAttrList,baseSaleDateList, SkuData, SkuInfoDate } from "./type";
//引入request
import { request } from "@/utils/request";
enum API{
    //获取已有spu数据
    HASSPU_URL="/admin/product/",
    //获取品牌数据
    ALLTRADMARK_URL="/admin/product/baseTrademark/getTrademarkList",
    //获取某一个spu下全部数据
    IMAGE_URL="/admin/product/spuImageList/",
    //获取SPU销售属性
    SALESPU_URL="/admin/product/spuSaleAttrList/",
    //获取整个项目所有的销售属性
    ALLSALEATTR_URL = "/admin/product/baseSaleAttrList",
    //添加SPU数据
    ADDSPU_URL = '/admin/product/saveSpuInfo',
    //更新已有SPU
    UPDATASPU_URL = '/admin/product/updateSpuInfo',
    //添加SKU商品
    ADDSAVESKU_URL = '/admin/product/saveSkuInfo',
    //查看某一个已有的SPU下的SKU
    SKUINFO_URL='/admin/product/findBySpuId/',
    //删除已有的SPU
    REMOVESPU_URL = '/admin/product/deleteSpu/'
}
//获取三级分类已有的SPU
export const reqHasSpu = (page:number,limit:number,category3Id:number|string)=>request.get<any,HasSpuResponseData>(API.HASSPU_URL+`${page}/${limit}?category3Id=${category3Id}`)
//获取全部的spu的品牌数据
export const reqAllTradmark = ()=>request.get<any,AllTradMark>(API.ALLTRADMARK_URL)
//获取某一个spu下所有的图片
export const reqSpuImageList = (apuId:number)=>request.get<any,SpuHasImg>(API.IMAGE_URL+apuId)
//获取已有spu的销售属性
export const reqSpuHasSaleAttr = (apuId:number)=>request.get<any,spuSaleAttrList>(API.SALESPU_URL+apuId)
//获取整个项目的所有销售属性
export const reqAllSaleAttr = ()=>request.get<any,baseSaleDateList>(API.ALLSALEATTR_URL)
//添加SPU数据
//data:SPU新增/已有spu对象
export const reqAddOrUpdateSpu = (data:SpuData)=>{
    if(data.id){
        return request.post<any,any>(API.UPDATASPU_URL,data)
    }else{
        return request.post<any,any>(API.ADDSPU_URL,data)
    }
}
//添加SKU商品
export const addSaveSku = (data:SkuData)=>request.post<any,any>(API.ADDSAVESKU_URL,data)

//查看已有SPU
export const reqSkuList = (spuId:number|string)=>request.get<any,SkuInfoDate>(API.SKUINFO_URL+spuId)

//删除SPU商品
export const reqRemoveSpu = (spuId:number|string)=>request.delete<any,any>(API.REMOVESPU_URL+spuId)













